﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Audio;
using System.Xml;
using System.IO;


// -----------------------------------------------------------------------
// <copyright file="$safeitemrootname$.cs" company="$registeredorganization$">
// TODO: Update copyright text.
// </copyright>
// -----------------------------------------------------------------------
namespace MenuGame2DXNA
{
    public class sMainGame : Scene
    {
        GameTime gametime;
        /// <summary>
        /// Kích thước pixcel màn hình
        /// </summary>
        private Vector2 ScreensSize;
        /// <summary>
        /// Kích thước pixcel của mỗi ô trên bản đồ
        /// </summary>
        private Vector2 CellSize;
        /// <summary>
        /// Kích thước ma trận bản đồ
        /// </summary>
        private Point MatrixSize;
        /// <summary>
        /// Lớp bản đồ
        /// </summary>
        private Tiles mapcell;
        /// <summary>
        /// Đối tượng game chính
        /// </summary>
        private Game game;
        /// <summary>
        /// Ma trận vật cản
        /// </summary>
        private short[,] Obstructions;
        /// <summary>
        /// Lớp Vật phẩm thưởng
        /// </summary>
        public Tiles bootyManager
        {
            get;
            private set;
        }
        /// <summary>
        /// Lớp Tường có thể bị bomb nổ
        /// </summary>
        private Tiles WallsManager;


        /// <summary>
        /// Gets the bomb manager.
        /// </summary>
        public BombManager bombManager
        {
            get;
            private set;
        }
        /// <summary>
        /// Trạng thái cũ của bàn phím
        /// </summary>
        private KeyboardState oldState;

         /// <summary>
        /// Nhân vật người chơi
        /// </summary>
        private BombPlayers character;

        public BombPlayers MainCharacter
        {
            get { return character; }
            set { character = value; }
        }

        /// <summary>
        /// Danh sách nhân vật tự động
        /// </summary>

        private List<Enemy> enemy;

        public List<Enemy> Enemy
        {
            get { return enemy; }
            set { enemy = value; }
        }

        /// <summary>
        /// 
        /// </summary>
        private VisibleEntityManager vEManager;
        /// <summary>
        /// Số lượng người chơi tự động
        /// </summary>
        private int nEnemy;

        /// <summary>
        /// 
        /// </summary>
        private GroupLayout LayoutMain;
        private GroupLayout LayoutPropertyPlayer;

        int countEnemyDeath;
        /// <summary>
        /// Loads the content.
        /// </summary>
        /// <param name="_game">The _game.</param>

        private GroupTextEntity Grouptext;

        private List<GroupTextEntity> GrouptextEnemy;
        private List<GroupLayout> LayoutPropertyEnemy;
        private TimeLine timeline;
        private int stage;
        private Dialog dialog;
        string[] filePaths;
        private  int MaxLevel = 5;

        private GameState StateGame;
        public enum GameState {PLAYING = 1, WIN ,FAIL ,GAMEOVER, VICTORY,NONE}
        List<string> FolderBombers;
        public override void LoadContent(Game _game)
        {
            filePaths = Directory.GetFiles(Directory.GetCurrentDirectory()+"\\Level");

            MaxLevel = filePaths.Count();
            isPlayMusic = false;
            game = _game;
            
            stage = 1;
            StateGame = GameState.NONE;
            
            Stop();
            XmlTextWriter xmlWriter =
             new XmlTextWriter("DVDList.xml", Encoding.UTF8);

            xmlWriter.Formatting = Formatting.Indented;
            xmlWriter.Indentation = 4;

            xmlWriter.WriteProcessingInstruction(
            "xml", "version='1.0' encoding='UTF-8'");


            for (var i = 0; i < MaxLevel;i++ )
            {
                xmlWriter.WriteComment(filePaths[i]);
            }

            // Close the stream
            xmlWriter.Close();
            //------------------------------------------
        }

        private void ChangeStage()
        {
            
            FolderBombers = new List<string>();
            FolderBombers.Add("White");
            FolderBombers.Add("Black");
            FolderBombers.Add("Blue");
            FolderBombers.Add("Red");
            // Khởi tạo các lớp trong bản đồ
            vEManager = new VisibleEntityManager();
            LayoutMain = new GroupLayout(game.Content, "LayoutMainGame.xml", "");
            LayoutPropertyPlayer = new GroupLayout(game.Content, "LayoutProperty.xml", ""); 
            // khởi tạo các thuộc tính cần thiết cho bản đồ
            MatrixSize = new Point(11, 11);

            CellSize = new Vector2(50, 50);

            ScreensSize = new Vector2(550, 550);

            //---------------------------------------------
            vEManager.AddObject(LayoutMain);
           
            XmlDocument _doc = new XmlDocument();
            _doc.Load(filePaths[stage - 1]);
            Obstructions = new short[MatrixSize.X, MatrixSize.Y];

            mapcell = new Tiles(1);
            XmlDocument mapxml = new XmlDocument();
            mapxml.LoadXml(_doc.SelectSingleNode("Level/Tiles[@name='map']").OuterXml);
            mapcell.InitFromXml(mapxml);
            mapcell.Init(game.Content, Obstructions, 1);
            mapcell.TopLeft = new Vector2(20, 30);


             XmlDocument wallxml = new XmlDocument();
            wallxml.LoadXml(_doc.SelectSingleNode("Level/Tiles[@name='wall']").OuterXml);
            WallsManager = new Tiles(1);
            WallsManager.InitFromXmlRandom(mapcell,new Point(0, 2),1,wallxml);
           
            WallsManager[new Point(0, 0)] = 0;
            WallsManager[new Point(0, 1)] = 0;
            WallsManager[new Point(1, 0)] = 0;
            WallsManager[new Point(0, 2)] = 0;

            WallsManager[new Point(7, 0)] = 0;
            WallsManager[new Point(6, 0)] = 0;
            WallsManager[new Point(8, 0)] = 0;
            WallsManager[new Point(8, 1)] = 0;

            WallsManager[new Point(8, 4)] = 0;
            WallsManager[new Point(8, 5)] = 0;
            WallsManager[new Point(8, 6)] = 0;
            WallsManager[new Point(7, 4)] = 0;
            WallsManager[new Point(7, 6)] = 0;

            WallsManager[new Point(8, 10)] = 0;
            WallsManager[new Point(7, 10)] = 0;
            WallsManager[new Point(6, 10)] = 0;
            WallsManager[new Point(6, 9)] = 0;
            WallsManager[new Point(6, 8)] = 0;
           
            WallsManager.TopLeft = new Vector2(20, 30);
            WallsManager.Init(game.Content, Obstructions, 0);


            XmlDocument bootyxml = new XmlDocument();
            bootyxml.LoadXml(_doc.SelectSingleNode("Level/Tiles[@name='booty']").OuterXml);
            bootyManager = new Tiles(0);
            bootyManager.InitFromXmlRandom(WallsManager, new Point(0, 5), 1, bootyxml);
            bootyManager.Init(game.Content, Obstructions, 0);
            bootyManager.TopLeft = new Vector2(20, 30);
            //----------------------------------------------

            //Khởi tạo các đối tượng quản lý trong bản đồ
            XmlElement timeboomxml =(XmlElement) _doc.SelectSingleNode("Level/Bomb");
            int timeBoom = int.Parse(timeboomxml.GetAttribute("TimeBomb"));
            bombManager = new BombManager(game.Content, Obstructions, WallsManager, CellSize, this,timeBoom);
            bombManager.TopLeft = new Vector2(20, 30);
            //-------------------------------------------

            //Khởi tạo đối tượng nhân vật người chơi
            character = new BombPlayers(game.Content, "Bomberman"+FolderBombers[game.IDColor]+ "/BomberMan", 33, new Vector2(0, 0), new Vector2(56, 58), this);
            character.SizeCell = CellSize;
            character.death_event += new Character.Death_handle(DeathCharacter);
            XmlElement pIndexXml = (XmlElement)_doc.SelectSingleNode("Level/Character/pIndex");
            character.pIndex = new Point(int.Parse(pIndexXml.GetAttribute("x")), int.Parse(pIndexXml.GetAttribute("y")));
            character.Score = 0;
            XmlElement ClifeXml = (XmlElement)_doc.SelectSingleNode("Level/Character/Life");
            character.Lifes = short.Parse(ClifeXml.InnerText);
            XmlElement RadiusXml = (XmlElement)_doc.SelectSingleNode("Level/Character/Radius");
            character.BombRadius = short.Parse(RadiusXml.InnerText);
            XmlElement nBombAllowXml = (XmlElement)_doc.SelectSingleNode("Level/Character/nBombAllow");
            character.nBombAllow = short.Parse(nBombAllowXml.InnerText);
            character.ID = 1;
            XmlElement SpeedsXml = (XmlElement)_doc.SelectSingleNode("Level/Character/Speed");
            character.Speeds = short.Parse(SpeedsXml.InnerText); 
            character.TopLeft = new Vector2(20, 30);

            Grouptext = new GroupTextEntity(game.Content, "GroupTextMainGame.xml");
            Grouptext[0].Rotation = -MathHelper.PiOver2;           
           Grouptext["player"].ColorText = GetColor(game.IDColor);
            FolderBombers.RemoveAt(game.IDColor);

            //-------------------------------------------

            // Khởi tạo các đối tượng nhân vật tự động

            List<Point> ListIndexEnemy = new List<Point>();
            ListIndexEnemy.Add(new Point(8, 0));
            ListIndexEnemy.Add(new Point(8, 5));
            ListIndexEnemy.Add(new Point(8, 10));

            enemy = new List<Enemy>();
            GrouptextEnemy = new List<GroupTextEntity>();
            LayoutPropertyEnemy = new List<GroupLayout>();
            XmlElement nEnemyXml = (XmlElement)_doc.SelectSingleNode("Level/Enemy/Amount");
            nEnemy = int.Parse(nEnemyXml.InnerText);
            for (int i = 0; i < nEnemy; i++)
            {
                GrouptextEnemy.Add(new GroupTextEntity(game.Content, "GroupTextMainGame.xml"));
                LayoutPropertyEnemy.Add(new GroupLayout(game.Content, "LayoutProperty.xml", ""));
                LayoutPropertyEnemy[i].TopLeft = new Vector2(0, (i + 1) * 120 + (i * 5));
                GrouptextEnemy[i].TopLeft = new Vector2(0, (i + 1) * 120 + (i * 5));
                GrouptextEnemy[i]["player"].Rotation = -MathHelper.PiOver2;
                GrouptextEnemy[i]["player"].Text = "C " + FolderBombers[i];
                 GrouptextEnemy[i]["player"].ColorText = GetColor(i);
                Enemy temp = new Enemy(game.Content, "Bomberman" + FolderBombers[i] + "/BomberMan", 33, Utilities.Index2Pixel(ListIndexEnemy[i]), new Vector2(56, 58), Obstructions, this);
                temp.death_event += new Character.Death_handle(DeathCharacter);
                temp.SizeCell = CellSize;
                temp.TopLeft = new Vector2(20, 30);
                temp.Score = 0;
                XmlElement EpIndexXml = (XmlElement)_doc.SelectSingleNode("Level/Enemy/pIndex");

                XmlElement ElifeXml = (XmlElement)_doc.SelectSingleNode("Level/Enemy/Life");
                temp.Lifes = short.Parse(ElifeXml.InnerText);
                XmlElement ERadiusXml = (XmlElement)_doc.SelectSingleNode("Level/Enemy/Radius");
                temp.BombRadius = short.Parse(ERadiusXml.InnerText);
                XmlElement EnBombAllowXml = (XmlElement)_doc.SelectSingleNode("Level/Enemy/nBombAllow");
                temp.nBombAllow = short.Parse(EnBombAllowXml.InnerText);
                XmlElement ESpeedsXml = (XmlElement)_doc.SelectSingleNode("Level/Enemy/Speed");
                temp.Speeds = short.Parse(ESpeedsXml.InnerText);
               
                
             
                temp.ID = i + 11;
                
                temp.pIndex = new Point(8, i * 5);
                enemy.Add(temp);
            }


            //-------------------------------------------

            // Khởi tạo các đối tượng đồ họa khác


          
            timeline = new TimeLine(game, 90);
            timeline.PositionStart = new Vector2(28, 0);
            countEnemyDeath = 0;
            vEManager.AddObject(mapcell);
            vEManager.AddObject(bootyManager);
            vEManager.AddObject(WallsManager);
            vEManager.AddObject(bombManager);
            vEManager.AddObject(character);
            
            vEManager.AddObject(Grouptext);
            vEManager.AddObject(LayoutPropertyPlayer);
            for (int i = 0; i < nEnemy;i++ )
            {
                vEManager.AddObject(GrouptextEnemy[i]);
                vEManager.AddObject(LayoutPropertyEnemy[i]);

            }
            vEManager.AddObject(timeline);
            StateGame = GameState.PLAYING;
        }

        private Color GetColor(int i)
        {
            Color colornew  = Color.White;
            switch (FolderBombers[i])
            {
                case "Black":
                    colornew = Color.Gray;
                    break;
                case "White":
                    colornew = Color.White;
                    break;
                case "Blue":
                    colornew = Color.Blue;
                    break;
                case "Red":
                    colornew = Color.Red;
                    break;
            }
            return colornew;
        }


        public override void Update(Microsoft.Xna.Framework.GameTime gameTime)
        {
            gametime = gameTime;
            if (!isPlayMusic)
            {
                isPlayMusic = true;
                MusicManager.Play("map1");
            }
            if (timeline.End == true && StateGame == GameState.PLAYING)
            {
                int MaxScore = enemy[0].Score;
                for (int i = 1; i < nEnemy; i++)
                {
                    if (enemy[i].Score > MaxScore && enemy[i].Death == false)
                        MaxScore = enemy[i].Score;
                }
                List<VisibleGameEntity> ListtextGameOver = new List<VisibleGameEntity>();
                TextEntity textGameOver = null;
                TextEntity textChangeStage = null;
                if (character.Score > MaxScore)
                {
                 
                    if (stage < MaxLevel)
                    {
                        stage++;
                         textGameOver = new TextEntity(game.Content, "YOU WIN");
                      
                        textChangeStage = new TextEntity(game.Content, "NEXT TO STAGE "+stage);
                       
                      StateGame = GameState.WIN;

                    }
                    else
                    {
                         textGameOver = new TextEntity(game.Content, "VICTORY!");

                         textChangeStage = new TextEntity(game.Content, "GO TO MENU");
                       
                        StateGame = GameState.VICTORY;
                    }
                }
                else
                {
                    textGameOver = new TextEntity(game.Content, "YOU FAIL!");
                    textChangeStage = new TextEntity(game.Content, "RETART STAGE "+stage);
                    StateGame = GameState.FAIL;
                }

                textChangeStage.Scale = 1.2f;
                textChangeStage.PositionStart = new Vector2(190, 220);
                TextEntity timecout = new TimeCount(game.Content, 3, gameTime, "0");
                timecout.Scale = 2f;
                timecout.PositionStart = new Vector2(310, 270);
                ListtextGameOver.Add(textChangeStage);
                ListtextGameOver.Add(timecout);
                textGameOver.ColorText = Color.Yellow;
                textGameOver.Scale = 2f;
                textGameOver.PositionStart = new Vector2(260, 160);
                ListtextGameOver.Add(textGameOver);
                dialog = new Dialog(game, ListtextGameOver, 400, 300, "", 6000, 100);
                dialog.Appear(54);
                vEManager.AddObject(dialog);
            }
            KeyboardState kbState = Keyboard.GetState();
            if (kbState.IsKeyDown(Keys.Escape))
            {
                game.Scene = 0;
                Pause();
            }
            if (StateGame == GameState.PLAYING)
            {
                if (character.Visible)
                {


                    if (kbState.IsKeyDown(Keys.Down))
                    {
                        Point DesPoint = new Point(character.pIndex.X + 1, character.pIndex.Y);
                        if (DesPoint.X < MatrixSize.X && Obstructions[DesPoint.X, DesPoint.Y] == 0)
                            character.MoveDown(false);
                    }
                    if (kbState.IsKeyDown(Keys.Up))
                    {
                        Point DesPoint = new Point(character.pIndex.X - 1, character.pIndex.Y);
                        if (DesPoint.X >= 0 && Obstructions[DesPoint.X, DesPoint.Y] == 0)
                            character.MoveUp(false);
                    }
                    if (kbState.IsKeyDown(Keys.Left))
                    {
                        Point DesPoint = new Point(character.pIndex.X, character.pIndex.Y - 1);
                        if (DesPoint.Y >= 0 && Obstructions[DesPoint.X, DesPoint.Y] == 0)
                            character.MoveLeft(false);
                    }
                    if (kbState.IsKeyDown(Keys.Right))
                    {
                        Point DesPoint = new Point(character.pIndex.X, character.pIndex.Y + 1);
                        if (DesPoint.Y < MatrixSize.Y && Obstructions[DesPoint.X, DesPoint.Y] == 0)
                            character.MoveRight(false);
                    }
                }



                if (kbState.IsKeyDown(Keys.Space))
                {
                    if (!oldState.IsKeyDown(Keys.Space))
                    {
                        character.AddBomb(gameTime);
                        if (bombManager.getRealBoomcount() >= 4)
                        {
                            for (int i = 0; i < nEnemy; i++)
                            {
                                enemy[i].FindPath(bombManager, WallsManager, 0, 0);
                            }
                        }
                    }
                }

                oldState = kbState;
                Grouptext["Score"].setNumber(character.Score, "00000", 50);
                Grouptext["Life"].Text = character.Lifes.ToString();
                Grouptext["nbomb"].Text = "x" + character.nBombAllow.ToString();
                Grouptext["Radius"].Text = "x" + character.BombRadius.ToString();
                for (int i = 0; i < nEnemy; i++)
                {
                    GrouptextEnemy[i]["Score"].setNumber(enemy[i].Score, "00000", 50);
                    GrouptextEnemy[i]["Life"].Text = enemy[i].Lifes.ToString();
                    GrouptextEnemy[i]["nbomb"].Text = "x" + enemy[i].nBombAllow.ToString();
                    GrouptextEnemy[i]["Radius"].Text = "x" + enemy[i].BombRadius.ToString();

                }
                for (int i = 0; i < nEnemy; i++)
                {
                    enemy[i].Distance = (int)Math.Sqrt((enemy[i].pIndex.X - character.pIndex.X) * (enemy[i].pIndex.X - character.pIndex.X) + (enemy[i].pIndex.Y - character.pIndex.Y) * (enemy[i].pIndex.Y - character.pIndex.Y));

                    enemy[i].PointCol = new List<Point>();
                    for (int j = 0; j < nEnemy; j++)
                        if (i != j)
                            enemy[i].PointCol.Add(enemy[j].pIndex);


                    if (enemy[i].Distance <= 1)
                    {
                        enemy[i].AddBomb(gameTime);
                        enemy[i].Path = new List<Point>();
                    }

                    if (Obstructions[enemy[i].pIndex.X, enemy[i].pIndex.Y] == i + 11)
                        enemy[i].pBom = enemy[i].pIndex;

                    if (bombManager.getRealBoomcount() < 4 && Obstructions[enemy[i].pBom.X, enemy[i].pBom.Y] != i + 11)
                    {
                        if ((enemy[i].pIndex.X + 1 < 11 && WallsManager[new Point(enemy[i].pIndex.X + 1, enemy[i].pIndex.Y)] == 1) ||
                            (enemy[i].pIndex.X - 1 >= 0 && WallsManager[new Point(enemy[i].pIndex.X - 1, enemy[i].pIndex.Y)] == 1) ||
                            (enemy[i].pIndex.Y + 1 < 11 && WallsManager[new Point(enemy[i].pIndex.X, enemy[i].pIndex.Y + 1)] == 1) ||
                            (enemy[i].pIndex.Y - 1 >= 0 && WallsManager[new Point(enemy[i].pIndex.X, enemy[i].pIndex.Y - 1)] == 1))
                        {
                            enemy[i].AddBomb(gameTime);
                            enemy[i].Path = new List<Point>();
                            break;
                        }
                        enemy[i].FindPathCharacter(bombManager, character.pIndex, WallsManager);

                    }



                    if (bombManager.getRealBoomcount() < 4 && Obstructions[enemy[i].pBom.X, enemy[i].pBom.Y] == i + 11
                        && (enemy[i].Path == null || (enemy[i].Path != null && enemy[i].Path.Count == 0)))
                    {
                        enemy[i].FindPath(bombManager, WallsManager, 0, 0);
                    }
                    if (enemy[i].Path != null && enemy[i].Path.Count >= 2)
                    {
                        enemy[i].pMove = enemy[i].Path[enemy[i].Path.Count - 2];
                    }

                    enemy[i].SetObstructions(Obstructions, enemy[i].pIndex, character.pIndex);
                    enemy[i].Update(gameTime, Color.White);
                }
                
            }
            else
            {

                if (dialog != null)
                {
                    dialog.Update(gameTime, Color.White);
                    if (dialog.State == Dialog.DialogState.ENDDISAPPEAR)
                    {
                        switch(StateGame)
                        {
                            case GameState.GAMEOVER:
                            case GameState.VICTORY:
                                {
                                    game.ScorePlayer= character.Score;
                                    game.Scene = 7;
                                    Stop();
                                    break;
                                }
                                
                            case GameState.FAIL:
                            case GameState.WIN:
                                ChangeStage();
                                break;
                        }
                    }
                }
            }
            vEManager.Update(gameTime, Color.White);
        }
        void DeathCharacter(object sender)
        {
            List<VisibleGameEntity> ListtextGameOver = new List<VisibleGameEntity>();
            TextEntity textGameOver = null;
            TextEntity textChangeStage = null;
            int IDCharacter = ((Character)sender).ID;
            if (IDCharacter > 1)
            {
                countEnemyDeath++;
                for (int i = 0; i < nEnemy; i++)
                {
                    if (enemy[i].ID == IDCharacter)
                    {
                        GrouptextEnemy[i]["player"].ColorText = Color.Black;
                        break;
                    }
                }
                    if (countEnemyDeath == enemy.Count)
                    {
                        if (stage < MaxLevel)
                        {
                            textGameOver = new TextEntity(game.Content, "YOU WIN");

                            stage++;
                            textChangeStage = new TextEntity(game.Content, "NEXT TO STAGE " + stage);
                            StateGame = GameState.WIN;


                        }
                        else
                        {
                            textGameOver = new TextEntity(game.Content, "VICTORY!");
                            textChangeStage = new TextEntity(game.Content, "GO TO MENU");
                            StateGame = GameState.VICTORY;
                        }
                        textChangeStage.Scale = 1.2f;
                        textChangeStage.PositionStart = new Vector2(190, 220);
                        TextEntity timecout = new TimeCount(game.Content, 3, gametime, "0");
                        timecout.Scale = 2f;
                        timecout.PositionStart = new Vector2(310, 270);
                        ListtextGameOver.Add(textChangeStage);
                        ListtextGameOver.Add(timecout);
                        textGameOver.ColorText = Color.Yellow;
                        textGameOver.Scale = 2f;
                        textGameOver.PositionStart = new Vector2(260, 160);
                        ListtextGameOver.Add(textGameOver);
                        dialog = new Dialog(game, ListtextGameOver, 400, 300, "", 6000, 100);
                        dialog.Appear(54);
                        vEManager.AddObject(dialog);
                    }
            }
            else
            {
                textGameOver = new TextEntity(game.Content, "GAMEOVER");
                textChangeStage = new TextEntity(game.Content, "GO TO MENU");
                StateGame = GameState.GAMEOVER;
                textChangeStage.Scale = 1.2f;
                textChangeStage.PositionStart = new Vector2(190, 220);
                TextEntity timecout = new TimeCount(game.Content, 3, gametime, "0");
                timecout.Scale = 2f;
                timecout.PositionStart = new Vector2(310, 270);
                ListtextGameOver.Add(textChangeStage);
                ListtextGameOver.Add(timecout);
                textGameOver.ColorText = Color.Yellow;
                textGameOver.Scale = 2f;
                textGameOver.PositionStart = new Vector2(260, 160);
                ListtextGameOver.Add(textGameOver);
                dialog = new Dialog(game, ListtextGameOver, 400, 300, "", 6000, 100);
                dialog.Appear(54);
                vEManager.AddObject(dialog);
               
            }
           
            
        }
        public override void Draw(GameTime gameTime, SpriteBatch spriteBatch)
        {         
            vEManager.Draw(gameTime, spriteBatch);
            for (int i = 0; i < nEnemy; i++)
            {
                enemy[i].Draw(gameTime, spriteBatch);
            }
           
        }
        public override void Play()
        {
            stage = 1;
            ChangeStage();
            base.Play();
        }
        public override void Pause()
        {           
            base.Pause();
        }
        public override void Stop()
        {
            stage = 1;
            base.Stop();
        }
        
    }
}
